#pragma once

#include <d3d11.h>
#include "Common.h"
#include "DeviceUserBase.h"
#include "Resource.h"


namespace Display
{

	class VertexBufferInfo
	{
	public:
		UINT count;
		UINT stride;
		UINT offset;
		UINT size;
	};

	class IndexBufferInfo
	{
	public:
		UINT count;
		UINT offset;
		UINT size;
	};

	enum BufferUsage
	{
		STATIC,
		DYNAMIC
	};

	enum BufferType
	{
		VERTEX,
		INDEX
	};
	
	class ResourcePool;

	class EXPORT Mesh : public Display::DeviceUserBase , public Resource
	{
		ID3D11Device * device;

		ID3D11Buffer * vertexBuffer;
		VertexBufferInfo vertsInfo;

		ID3D11Buffer * indexBuffer;
		IndexBufferInfo indeciesInfo;

		friend class ResourcePool;

		

		
		static Mesh * Create(ID3D11Device * device,ResourcePool * pool);
	public:
		 
	   Mesh(ResourcePool * pool);
	   ~Mesh(void);
	    void Draw();
	    void DrawIndexed();

	  
	   //Buffer creation and allocation

	    void AllocateVertexBuffer(UINT size,BufferUsage usage);
	    void AllocateIndexBuffer(UINT size,BufferUsage usage);

	    void AllocateAndFillVertexBuffer(UINT size,UINT stride,UINT count,UINT offset,BufferUsage usage,void * data);
	    void AllocateAndFillIndexBuffer(UINT size,UINT count,UINT offset,BufferUsage usage,void * data);

	    void FillVertexBuffer(UINT stride,UINT count,UINT offset,void * data);
	    void FillIndexBuffer(UINT count,UINT offset,void * data);

	   

	   //----------
	   
	private:
		void Bind();

		D3D11_BUFFER_DESC GetBufferDesc(UINT size,BufferUsage usage,BufferType type);
		void Dispose();
		void OnZeroRefReach();
	};
}
